package com.appspot.etao.model;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.appspot.etao.Constant;
import com.appspot.etao.util.StringUtil;
import com.taobao.top.domain.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class UserModel extends BaseModel {

	private static final long serialVersionUID = 7710944326861558809L;
	
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;
    
    /** 用户编号 */
    @Persistent
	private Long userId;

    /** 用户昵称 */
    @Persistent
	private String nick;

    /** 用户性别 */
    @Persistent
	private String sex;

    /** 卖家信用 */
    @Persistent
	public UserCreditModel sellerCredit;

    /** 买家信用 */
    @Persistent
	public UserCreditModel buyerCredit;

    /** 用户当前居住地公开信息 */
    @Persistent
	private LocationModel location;

    /** 最近登陆时间 */
    @Persistent
	private String lastVisit;

    /** 用户生日日期 */
    @Persistent
	private String birthday;

    /** 用户类型 */
    @Persistent
	private String type;

    /** 是否购买多图服务 */
    @Persistent
	private Boolean hasMorePic;

    /** 可上传商品图片数量 */
    @Persistent
	private Integer itemImgNum;

    /** 单张商品图片最大容量 */
    @Persistent
	private Integer itemImgSize;

    /** 可上传属性图片数量 */
    @Persistent
	private Integer propImgNum;

    /** 单张销售属性图片最大容量 */
    @Persistent
	private Integer propImgSize;

    /** 是否受限制 */
    @Persistent
	private String autoRepost;

    /** 有无实名认证 */
    @Persistent
	private String promotedType;

    /** 用户账号状态 */
    @Persistent
	private String status;

    /** 有无绑定支付宝 */
    @Persistent
	private String alipayBind;

    /** 是否参加消保 */
    @Persistent
	private String consumerProtection;
    
    @Persistent
    private Date created;

	private User user;

	public UserModel() {
    	
    }
    
    public UserModel(User user) {
    	setUser(user);
    }
    
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public UserCreditModel getSellerCredit() {
		return sellerCredit;
	}

	public void setSellerCredit(UserCreditModel sellerCredit) {
		this.sellerCredit = sellerCredit;
	}

	public UserCreditModel getBuyerCredit() {
		return buyerCredit;
	}

	public void setBuyerCredit(UserCreditModel buyerCredit) {
		this.buyerCredit = buyerCredit;
	}

	public LocationModel getLocation() {
		return location;
	}

	public void setLocation(LocationModel location) {
		this.location = location;
	}

	public String getLastVisit() {
		return lastVisit;
	}

	public void setLastVisit(String lastVisit) {
		this.lastVisit = lastVisit;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Boolean getHasMorePic() {
		return hasMorePic;
	}

	public void setHasMorePic(Boolean hasMorePic) {
		this.hasMorePic = hasMorePic;
	}

	public Integer getItemImgNum() {
		return itemImgNum;
	}

	public void setItemImgNum(Integer itemImgNum) {
		this.itemImgNum = itemImgNum;
	}

	public Integer getItemImgSize() {
		return itemImgSize;
	}

	public void setItemImgSize(Integer itemImgSize) {
		this.itemImgSize = itemImgSize;
	}

	public Integer getPropImgNum() {
		return propImgNum;
	}

	public void setPropImgNum(Integer propImgNum) {
		this.propImgNum = propImgNum;
	}

	public Integer getPropImgSize() {
		return propImgSize;
	}

	public void setPropImgSize(Integer propImgSize) {
		this.propImgSize = propImgSize;
	}

	public String getAutoRepost() {
		return autoRepost;
	}

	public void setAutoRepost(String autoRepost) {
		this.autoRepost = autoRepost;
	}

	public String getPromotedType() {
		return promotedType;
	}

	public void setPromotedType(String promotedType) {
		this.promotedType = promotedType;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getAlipayBind() {
		return alipayBind;
	}

	public void setAlipayBind(String alipayBind) {
		this.alipayBind = alipayBind;
	}

	public String getConsumerProtection() {
		return consumerProtection;
	}

	public void setConsumerProtection(String consumerProtection) {
		this.consumerProtection = consumerProtection;
	}
    
    public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

    public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
		
		this.userId = user.getUserId();
		this.nick = StringUtil.cut(user.getNick());
		this.sex = user.getSex();
		this.sellerCredit = new UserCreditModel(user.getSellerCredit());
		this.buyerCredit = new UserCreditModel(user.getBuyerCredit());
		this.location = new LocationModel(user.getLocation());
		this.created = user.getCreated();
		this.lastVisit = user.getLastVisit();
		this.birthday = user.getBirthday();
		this.type = StringUtil.cut(user.getType());
		this.hasMorePic = user.getHasMorePic();
		this.itemImgNum = user.getItemImgNum();
		this.itemImgSize = user.getItemImgSize();
		this.propImgNum = user.getPropImgNum();
		this.propImgSize = user.getPropImgSize();
		this.autoRepost = StringUtil.cut(user.getAutoRepost());
		this.promotedType = StringUtil.cut(user.getPromotedType());
		this.status = StringUtil.cut(user.getStatus());
		this.alipayBind = StringUtil.cut(user.getAlipayBind());
		this.consumerProtection = StringUtil.cut(user.getConsumerProtection());
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer("");
		sb.append("[");
		sb.append(nick);
		sb.append(",");
		sb.append(sex);
		sb.append(",");
		sb.append(buyerCredit);
		sb.append(",");
		sb.append(sellerCredit);
		sb.append(",");
		sb.append(location);
		sb.append(",");
		sb.append(Constant.FORMATER.format(created));
		sb.append(",");
		sb.append(lastVisit);
		sb.append(",");
		sb.append(birthday);
		sb.append(",");
		sb.append(type);
		sb.append(",");
		sb.append(hasMorePic);
		sb.append(",");
		sb.append(itemImgNum);
		sb.append(",");
		sb.append(itemImgSize);
		sb.append(",");
		sb.append(propImgNum);
		sb.append(",");
		sb.append(propImgSize);
		sb.append(",");
		sb.append(autoRepost);
		sb.append(",");
		sb.append(promotedType);
		sb.append(",");
		sb.append(status);
		sb.append(",");
		sb.append(alipayBind);
		sb.append(",");
		sb.append(consumerProtection);
		sb.append("]");

		return sb.toString();
	}
}
